package com.hrzyit.whistle.comm.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.hrzyit.whistle.comm.R
import com.hrzyit.whistle.comm.data.bean.ContactEntity
import kotlinx.android.synthetic.main.item_contact.view.*
import kotlinx.android.synthetic.main.item_index_contacts.view.*
import me.yokeyword.indexablerv.IndexableAdapter

/**
 * 索引选择器适配器
 * @author YangWei
 * @date 2019/3/29
 */
class ContactsAdapter(context:Context):IndexableAdapter<ContactEntity>(){

    var mInflater: LayoutInflater = LayoutInflater.from(context)


    override fun onCreateTitleViewHolder(parent: ViewGroup?): RecyclerView.ViewHolder {
        val view = mInflater.inflate(R.layout.item_index_contacts, parent, false)
        return IndexVH(view)
    }

    override fun onCreateContentViewHolder(parent: ViewGroup?): RecyclerView.ViewHolder {
        val view = mInflater.inflate(R.layout.item_contact, parent, false)
        return ContentVH(view)
    }

    // 绑定行数据
    override fun onBindContentViewHolder(holder: RecyclerView.ViewHolder?, entity: ContactEntity?) {
        var vh = holder as ContentVH
        vh.mNameTv.text = entity?.name
//        vh.tvMobile.text = entity?.mobile

    }

    // 绑定索引数据
    override fun onBindTitleViewHolder(holder: RecyclerView.ViewHolder?, indexTitle: String?) {
        var vh = holder as IndexVH
        vh.mIndexTv.text = indexTitle
    }

    private  class IndexVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var mIndexTv: TextView = itemView.mIndexTv as TextView

    }

    private class ContentVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
         var mNameTv: TextView = itemView.mNameTv as TextView
//         var tvMobile: TextView = itemView.tv_mobile as TextView

    }

}